package com.web.news.junit;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.web.news.mapper.NewsMapper;
import com.web.news.pojo.News;
import com.web.news.utils.MyBatisUtil;

public class Testnews {
		@Test
		public void test1() {
			SqlSession session = MyBatisUtil.getSession();
			NewsMapper newsMapper = session.getMapper(NewsMapper.class);
			List<News> list = newsMapper.selectByExample(null);
			for(News news : list) {
				System.out.println(news.getNtitle());
			}
			session.close();
		}
		
		@Test
		public void test2() {
			SqlSession session = MyBatisUtil.getSession();
			NewsMapper newsMapper = session.getMapper(NewsMapper.class);
			
			int pageNum = 2;
			int pageSize= 5;
			
			PageHelper.startPage(pageNum,pageSize);
			List<News> list = newsMapper.selectByExample(null);
			
			for(News news : list) {
				System.out.println(news.getNid() + "," + news.getNtitle());
			}
			
			PageInfo page = new PageInfo<>(list);
			System.out.println("总记录数" + page.getTotal());
			System.out.println("总页数" + page.getPages());
			System.out.println("上页" + page.getPrePage());
			System.out.println("下页" + page.getNextPage());
			session.close();
		}
		
}
